#include <stdio.h>
#include <stdint.h>
#include <wiringPi.h>
#include <wiringSerial.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h> 
#include <string.h>

#define SERIAL_BANDRATE 115200
int fdUart=0;
int initUart(void)
{
  if(wiringPiSetup()<0)
    return 1;
  if((fdUart=serialOpen("/dev/ttyAMA0",SERIAL_BANDRATE))<0)
    return 2;
	  /*block configuration */
  //int flags = fcntl(fd, F_SETFL, O_NONBLOCK);
  //fcntl(fd, F_SETFL, flags | O_NONBLOCK);
  printf("serial start band rate:%d\n",SERIAL_BANDRATE);	
  return 0;
}

int main()
{
  initUart();
  while(1)
  while(serialDataAvail(fdUart))
  {
    char temp = serialGetchar(fdUart);
    putchar(temp);
  }
  while(1)
  while(serialDataAvail(fdUart))
  {
    char temp = serialGetchar(fdUart);
    putchar(temp);
  }
  return 0;
}
